package main

import (
	"./BlockChain"
	"fmt"
	"time"
)

func main() {
	//创建区块链并创建创世区块
	blockChain := BlockChain.CreateGenesisBlockWithChain("Genesis block")

	//添加区块1
	blockChain.AddBlockToBlockChain(
		//区块高度
		int64(len(blockChain.Block)) + 1,
		//交易数据
		"Second block",
		//上一个区块的哈希
		blockChain.Block[len(blockChain.Block) - 1].Hash,
	)

	//添加区块2
	blockChain.AddBlockToBlockChain(
		//区块高度
		int64(len(blockChain.Block)) + 1,
		//交易数据
		"Second block",
		//上一个区块的哈希
		blockChain.Block[len(blockChain.Block) - 1].Hash,
	)

	//遍历输出区块信息
	for _,block := range blockChain.Block {
		fmt.Println("")
		fmt.Printf("区块的高度：%d\n", block.Height)
		fmt.Printf("交易数据：%s\n", block.Data)
		fmt.Printf("时间戳：%s\n", time.Unix(block.Timestamp, 0).Format("2006-01-02 03:04:05 PM"))
		fmt.Printf("上一个区块的哈希：%x\n", block.PrevHash)
		fmt.Printf("Hash：%x\n", block.Hash)
		fmt.Printf("Nonce: %d\n", block.Nonce)
		fmt.Println("-------------------------------")
	}
}
